package com.xyht.sca_s.student_manage_system.modules.user.controller;


import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.user.entity.req.RoleUserReq;
import com.xyht.sca_s.student_manage_system.modules.user.entity.req.SmsRoleReq;
import com.xyht.sca_s.student_manage_system.modules.user.service.SmsRoleService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色信息 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/role")
@SecretBody
public class SmsRoleController {
    @Autowired
    private SmsRoleService smsRoleService;

    @ApiModelProperty(value = "获取角色列表")
    @GetMapping("/get")
    public ResponseResult getRoleList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        return smsRoleService.getRoleList(pageSize, pageNum);
    }

    @ApiModelProperty(value = "获取角色详情")
    @GetMapping("/detail")
    public ResponseResult getRoleList(@RequestParam("role_id") String role_id) {
        return smsRoleService.getRoleByID(role_id);
    }

    @ApiModelProperty(value = "添加角色")
    @PostMapping("/add")
    public ResponseResult addRole(@RequestBody SmsRoleReq smsRoleReq) {
        return smsRoleService.addRole(smsRoleReq);
    }

    @ApiModelProperty(value = "更新角色信息")
    @PostMapping("/update")
    public ResponseResult updateRole(@RequestBody SmsRoleReq smsRoleReq) {
        return smsRoleService.updateRole(smsRoleReq);
    }

    @ApiModelProperty(value = "删除角色信息")
    @PostMapping("/delete")
    public ResponseResult deleteRole(@RequestBody SmsRoleReq smsRoleReq) {
        return smsRoleService.deleteRole(smsRoleReq.getId());
    }


    @ApiModelProperty(value = "获取角色用户列表")
    @GetMapping("/userList")
    public ResponseResult getRoleUserList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam("role_id") String role_id) {
        return smsRoleService.getRoleUserList(role_id, pageNum, pageSize);
    }

    @ApiModelProperty(value = "添加角色用户信息")
    @PostMapping("/addRoleUser")
    public ResponseResult addRoleUser(@RequestBody RoleUserReq roleUserReq) {
        return smsRoleService.addRoleUser(roleUserReq);
    }

    @ApiModelProperty(value = "删除角色用户信息")
    @PostMapping("/deleteRoleUser")
    public ResponseResult deleteRoleUser(@RequestBody RoleUserReq roleUserReq) {
        return smsRoleService.deleteRoleUser(roleUserReq);
    }

}

